<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of tt_crossr</title>
  <meta name="keywords" content="tt_crossr">
  <meta name="description" content="One right-to-left sweep of the TT-cross method.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">cross</a> &gt; tt_crossr.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/cross&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>tt_crossr
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>One right-to-left sweep of the TT-cross method.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [tt,ind_right]=tt_crossr(arr,ind_left) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">One right-to-left sweep of the TT-cross method.
   [TT,IND_RIGHT]=TT_CROSSR(D,N,FUN,IND_LEFT) Computes one QR-maxvol sweep
   of the TT-cross method. The input is the pair (D,N) that determines the
   size of the tensor, FUN is the function handle to evaluate a particular
   element of the tensor, i.e., VAL=FUN(IND). To pass parameters, please
   use anonymous function handles in MATLAB. 
 


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-matrix to TT1 cell-array format</li><li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-tensor TT1 to old-cell array format.</li><li><a href="../../tt2/@tt_tensor/qr.html" class="code" title="function [tt,rm]=qr(tt,op)">qr</a>	Left and right orthogonalization of the TT-format</li><li><a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li><li><a href="../../tt2/core/maxvol2.html" class="code" title="function [ind]=maxvol2(a,ind)">maxvol2</a>	Maximal volume submatrix in an tall matrix</li><li><a href="../../tt2/core/tt_ind2sub.html" class="code" title="function [ind] = tt_ind2sub(siz,ndx)">tt_ind2sub</a>	Correct conversion of an index to a multiindex</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [tt,ind_right]=tt_crossr(arr,ind_left)</a>
0002 <span class="comment">%One right-to-left sweep of the TT-cross method.</span>
0003 <span class="comment">%   [TT,IND_RIGHT]=TT_CROSSR(D,N,FUN,IND_LEFT) Computes one QR-maxvol sweep</span>
0004 <span class="comment">%   of the TT-cross method. The input is the pair (D,N) that determines the</span>
0005 <span class="comment">%   size of the tensor, FUN is the function handle to evaluate a particular</span>
0006 <span class="comment">%   element of the tensor, i.e., VAL=FUN(IND). To pass parameters, please</span>
0007 <span class="comment">%   use anonymous function handles in MATLAB.</span>
0008 <span class="comment">%</span>
0009 <span class="comment">%</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0012 <span class="comment">%</span>
0013 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0014 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0015 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0016 <span class="comment">%</span>
0017 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0018 <span class="comment">%ivan.oseledets@gmail.com</span>
0019 <span class="comment">%---------------------------</span>
0020 
0021 d=arr{1};
0022 sz=arr{2};
0023 <span class="comment">%arr1=arr(:);</span>
0024 tt=cell(d,1);
0025 ind_right=cell(d,1); <span class="comment">%Computed ind_right</span>
0026 ind_l=ind_left{d-1};
0027 r1=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(ind_l,2);
0028 ncur=sz(1);
0029 mat=zeros(ncur,r1);
0030 <span class="keyword">for</span> j=1:ncur
0031    <span class="keyword">for</span> s=1:r1
0032       ind_f=[ind_l(:,s)',j];
0033       <span class="comment">%mat(j,s)=arr1(sub_to_ind(ind_f,sz));</span>
0034       val=my_elem(ind_f,arr); 
0035       mat(j,s)=val;
0036    <span class="keyword">end</span>
0037 <span class="keyword">end</span>
0038 [qs,rs]=<a href="../../tt2/@tt_tensor/qr.html" class="code" title="function [tt,rm]=qr(tt,op)">qr</a>(mat,0);
0039 ind=<a href="../../tt2/core/maxvol2.html" class="code" title="function [ind]=maxvol2(a,ind)">maxvol2</a>(qs);
0040 ind_right{d-1}=ind;
0041 <span class="comment">%mat=mat*inv(mat(ind,:));</span>
0042 mat=qs*inv(qs(ind,:));
0043 tt{d}=mat;
0044 
0045 <span class="keyword">for</span> k=(d-1):-1:2
0046      ncur=sz(k);
0047      ind_l=ind_left{k-1};
0048      ind_r=ind_right{k};
0049      r2=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(ind_l,2);
0050      r3=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(ind_r,2);
0051      <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=zeros(ncur,r2,r3);
0052      <span class="comment">%fprintf('k=%d \n');</span>
0053      <span class="keyword">for</span> i=1:ncur
0054          <span class="keyword">for</span> s2=1:r2
0055              <span class="keyword">for</span> s3=1:r3
0056                  ind_f=[ind_l(:,s2)',i,ind_r(:,s3)'];
0057                  val=my_elem(ind_f,arr); 
0058                  <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>(i,s2,s3)=val;
0059                  <span class="comment">%core(i,s2,s3)=arr1(sub_to_ind(ind_f,sz));</span>
0060 
0061              <span class="keyword">end</span>
0062          <span class="keyword">end</span>
0063      <span class="keyword">end</span>
0064      <span class="comment">%core is ncurxr2xr3, from the left we need</span>
0065      <span class="comment">%r2xncurxr3, but from the right</span>
0066      <span class="comment">%we need (ncurxr3)xr2 or (r3xncur)xr2</span>
0067      <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=permute(<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>,[3,1,2]); <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>,[r3*ncur,r2]);
0068      rnew=min(r2,r3*ncur);
0069      [qs,rs]=<a href="../../tt2/@tt_tensor/qr.html" class="code" title="function [tt,rm]=qr(tt,op)">qr</a>(<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>,0);
0070      ind=<a href="../../tt2/core/maxvol2.html" class="code" title="function [ind]=maxvol2(a,ind)">maxvol2</a>(qs);
0071      ind_old=ind_right{k};
0072      ind_new=zeros(d-k+1,rnew);
0073      ncur=sz(k);
0074      <span class="keyword">for</span> s=1:rnew
0075         f_in=ind(s);
0076         w1=<a href="../../tt2/core/tt_ind2sub.html" class="code" title="function [ind] = tt_ind2sub(siz,ndx)">tt_ind2sub</a>([r3,ncur],f_in);
0077         rs=w1(1); js=w1(2);
0078         ind_new(:,s)=[js,ind_old(:,rs)'];
0079      <span class="keyword">end</span>
0080      ind_right{k-1}=ind_new;
0081      <span class="comment">%core=core*inv(core(ind,:));</span>
0082      <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=qs*inv(qs(ind,:));
0083      
0084      <span class="comment">% core=reshape(core,[r2,ncur,r3]); core=permute(core,[2,1,3]);</span>
0085      <span class="comment">% core=reshape(core,[ncur,r3,r2]); core=permute(core,[1,3,2]);</span>
0086      <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>,[r3,ncur,rnew]); <a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=permute(<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>,[2,3,1]);
0087    
0088     tt{k}=<a href="../../tt2/@tt_matrix/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>;
0089 <span class="keyword">end</span>
0090 ncur=sz(1);
0091 ind_r=ind_right{1};
0092 r=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(ind_r,2);
0093 mat=zeros(ncur,r);
0094 <span class="keyword">for</span> i=1:ncur
0095     <span class="keyword">for</span> s=1:r
0096       ind_f=[i,ind_r(:,s)'];
0097       val=my_elem(ind_f,arr);
0098       mat(i,s)=val;
0099       <span class="comment">%mat(i,s)=arr1(sub_to_ind(ind_f,sz));</span>
0100     <span class="keyword">end</span>
0101 <span class="keyword">end</span>
0102 tt{1}=mat;
0103 <span class="comment">%for k=1:d</span>
0104 <span class="comment">%     res=tt{k}-tt_true{k};</span>
0105 <span class="comment">%    res=res(:);</span>
0106 <span class="comment">%    fprintf('k=%d, approximation error: %e \n',k,norm(res));</span>
0107 <span class="comment">%end</span>
0108 <span class="keyword">return</span>
0109 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>